#!/usr/bin/env python2

from exceptions import *
from log import *

import os
import time
import abc
import csv
import sys

def className(name):
	def setClassName(obj):
		obj.className = name
		return obj
	return setClassName

def appParams(params):
	def setAppParams(obj):
		obj.appParams = params
		return obj
	return setAppParams

def JVMOptions(options):
	def setOptions(obj):
		obj.jvmOptions += options
		return obj
	return setOptions

@JVMOptions(['-XX:+PrintCompilation', '-XX:+PrintGCDetails', '-XX:+UnlockDiagnosticVMOptions', '-XX:+PrintInlining', '-XX:+PrintCommandLineFlags'])
#@JVMOptions(['-XX:+PrintCompilation', '-XX:+PrintGCDetails', '-XX:+UnlockDiagnosticVMOptions', '-XX:+PrintInlining'])
class benchmarker(object):

	className = ''

	jvmOptions = []

	appParams = {}

	binDir = '../bin/'

	outputBuffer = 'tmp.output'

	def __init__(self):
		pass

	def __getCMD__(self):
		cmd = ['java']
		cmd += self.jvmOptions
		cmd.append(self.className)
		appParamList = []
		for k, v in self.appParams.items():
			appParamList.append(k + '=' + str(v))

		cmd += appParamList
		return ' '.join(cmd)

	def run(self):
#		print(self.__getCMD__())
		os.chdir(self.binDir)
		os.system(self.__getCMD__() + ' > ' + self.outputBuffer)
#		os.system(self.__getCMD__())
		pass

	def getResult(self):
		result = []
		with open(self.outputBuffer) as f:
			result = f.read()
			l = Log(result)
			return l.getResult()



	
def main():

	b = benchmarker()
	b.run()


if __name__ == '__main__':
	main()


# -------------------------

